package com.rolerealm;

import com.rolerealm.service.CharacterService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * RoleRealm AI角色扮演网站后端应用启动类
 * 
 * @author RoleRealm Team
 * @version 1.0.0
 */
@SpringBootApplication
public class RoleRealmApplication {

    public static void main(String[] args) {
        SpringApplication.run(RoleRealmApplication.class, args);
    }

    @Autowired(required = false)
    private CharacterService characterService;

    // 应用启动后自动初始化预设角色（若不存在）
    @EventListener(ApplicationReadyEvent.class)
    public void initPresetCharactersIfEmpty() {
        try {
            if (characterService != null) {
                characterService.initPresetCharacters();
            }
        } catch (Exception ignored) {}
    }
}

